﻿using LxBasic;
using System.Collections.Generic;

namespace LxCore
{
    public class SolveCenter : JsObject
    {
        public WallDistanceSolver.Set WallDistanceSolver = new();
        public TemperatureSolver.Set TemperatureSolver = new();
        public SIMPLESolver.Set SIMPLESolver = new();
        public TurbulenceSolver.Set TurbulenceSolver = new();
        public RadiationSolver.Set RadiationSolver = new();
        public void ClearSolver()
        {
            TemperatureSolver.ClearSolver();
            SIMPLESolver.ClearSolver();
            TurbulenceSolver.ClearSolver();
            RadiationSolver.ClearSolver();
        }
        public void CheckCreate()
        {
            TemperatureSolver.CheckCreate();
            SIMPLESolver.CheckCreate();
            TurbulenceSolver.CheckCreate();
            RadiationSolver.CheckCreate();
        }
        public void Initialize()
        {
            WallDistanceSolver.Initialize();
            TemperatureSolver.Initialize();
            SIMPLESolver.Initialize();
            TurbulenceSolver.Initialize();
            RadiationSolver.Initialize();
        }
        public void Solve_Steady()
        {
            TurbulenceSolver.UpdateGammaForMomentum();
            SIMPLESolver.Solve_Steady();
            TurbulenceSolver.Solve_Steady();

            TurbulenceSolver.UpdateGammaForTemperature();
            TemperatureSolver.Solve_Steady();
            solveRadiation();
        }
        public void Solve_ImplicitTrans()
        {
            TurbulenceSolver.UpdateGammaForMomentum();
            SIMPLESolver.Solve_ImplicitTrans();
            TurbulenceSolver.Solve_ImplicitTrans();
            TurbulenceSolver.UpdateGammaForTemperature();
            TemperatureSolver.Solve_ImplicitTrans();
        }
        public void Solve_ExplicitTrans()
        {
            TemperatureSolver.Solve_ExplicitTrans();
        }
        public void SaveOldValue()
        {
            SIMPLESolver.SaveOldValue();
            TemperatureSolver.SaveOldValue();
        }
        protected void solveRadiation()
        {
            foreach (var l in RadiationSolver.Solvers) { l.Solve_Steady(); }
        }
    }
}
//protected void updateGammaForMomentum()
//{
//    MultiThreads.RunParallelTask((i) =>
//    {
//        foreach (var l in TurbulenceSolver.Solvers) { l.UpdateGammaForMomentum(i); }
//    });
//}
//protected void updateGammaForTemperature()
//{
//    MultiThreads.RunParallelTask((i) =>
//    {
//        foreach (var l in TurbulenceSolver.Solvers) { l.UpdateGammaForTemperature(i); }
//    });
//}
//InitializeGroup.Clear();
//WallDistanceGroup.ClearSolver();//实际上下一次计算自动更新掉就的，但是，如果导入新网格，则需要清理内存
//public InitializationSolver InitializeGroup = new();
